package tw.fc.agui;

import static tw.fc.Std.iRound ;
import android.view.MotionEvent;

public abstract class GrObj {

   //[ =========  static part   =======================

   public static double PI=Math.PI;
   public static double PI2=Math.PI*2;
   public static double sqrt2=Math.sqrt(2);

   //[ 公用, 因為全電腦只有一隻mouse
   public static final MuV2D lastMousePos=new MuV2D();          

   //---------------------------------

//   public static final ImuV2D lastMousePos() {  return lastMousePos; }

/////   public static int round(double d) {  return (int)Math.round(d);  }
/////   public static double cos(double d) {  return Math.cos(d);  }
/////   public static double sin(double d) {  return Math.sin(d);  }
/////   public static double tan(double d) {  return Math.tan(d);  }

   static double rangeCorrection(double sine) {
      //: 原為 class Space3D的static方法double correctingSine(double)
      //:
      //: 使用Math.asin(s), 在s為1.0時因誤差而使函數值為NaN. 
      //: 此bug除錯達數小時.     20040509
      //:                                              
      if(sine>1.0) {
         if(sine>1.001) {
            throw new IllegalArgumentException("range error: "+sine);
         }
         return 1.0;  //: floating error correction
      }
      if(sine<-1.0) {
         if(sine<-1.001) {
            throw new IllegalArgumentException("range error: "+sine);
         }
         return -1.0;  //: floating error correction
      } 
      return sine;
   }
 //[ 移入class Std, 此段不刪備搜
// public static double a_sin(double d) {  
//    return Math.asin(rangeCorrection(d));  
// }
// public static double a_cos(double d) {  
//    return Math.acos(rangeCorrection(d));  
// }

   //[  deprecated, 應使用 class XYW 的 seyBy(c, r)
   public static void setXYW(ImuV2D c, double r, int[] dst) {
   // 由圓心及半徑求外接正方形的x,y,w
      dst[0]=iRound(c.x()-r);
      dst[1]=iRound(c.y()-r);
      dst[2]=iRound(r*2);
   } 

   //] =========  static part   =======================


   //[ =========  instance part  ====================

   public boolean visible=true;  //: 鼓勵直接取用

   //[ 可避免常new , 但多緒時要小心
   protected final MuV2D tempVec=new MuV2D(); 

   //---------------------------------

//    public ImuV2D getPosition() { 
//       //: 可能不用. 若使用就須override. 例如 Eye.paintTo 會用到
//       throw new RuntimeException("\n\nnot overrided in subclass of GrObj\n");
//    }
   public boolean contains(tw.fc.agui.ImuV2D at) {
      return false;  //: 預設成不佔空間. 通常要override.
   }



   public void setPanelForChildren() {  
      ;               //: may be overriden in subclass 
   } 

   public void forFling(android.view.MotionEvent e1, 
                        android.view.MotionEvent e2, 
                        float velocityX, float velocityY)        {}
   public void forScroll(android.view.MotionEvent e1, 
                         android.view.MotionEvent e2, 
                         float velocityX, float velocityY)       {}
   public void forDown(android.view.MotionEvent e)               {}
   public void forDoubleTap(android.view.MotionEvent e)          {}
   public void forDoubleTapEvent(android.view.MotionEvent e)     {}
   public void forSingleTapConfirmed(android.view.MotionEvent e) {}
   public void forSingleTapUp(android.view.MotionEvent e)        {}
   public void forLongPress(android.view.MotionEvent e)          {}
   public void forShowPress(android.view.MotionEvent e)          {}
   public void forMove(android.view.MotionEvent e)               {}
   public void forRelease(android.view.MotionEvent e)            {}
   public void forMultiTouchDown(android.view.MotionEvent e)     {}
   public void forMultiTouchUp(android.view.MotionEvent e)       {}


   //[ =========  instance part  ====================

}